//
//  HeadViewController.m
//  智慧小区
//
//  Created by 高永杨 on 2017/3/16.
//  Copyright © 2017年 zhongchuang. All rights reserved.
//

#import "HeadViewController.h"
#import <SDCycleScrollView.h>
#import "GyyImagCenter.h"
#import "HeadVieCell.h"
#import "GongGaoVC.h"
#import "LovingHeartVC.h"
#import <MJRefresh.h>
#import "NewViewContro.h"
#import "PlotSearchVC.h"
#import "HandyServicVC.h"
#import "ComMallViewController.h"
@interface HeadViewController ()<SDCycleScrollViewDelegate,UITextFieldDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
/**<#参数意思#>*/
@property(nonatomic,strong)NSMutableArray *textArr;
/**<#参数意思#>*/
@property(nonatomic,strong)NSMutableArray *imageArr;

@end
static NSString *cellStr = @"collect";
static NSString *headerId = @"headerId";
@implementation HeadViewController

- (void)viewDidLoad {
    [super viewDidLoad];

//    [self.view addSubview:cycleScrollView];
    self.navigationController.navigationBar.translucent = NO;
//    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:18/255. green:121/255. blue:201/255. alpha:YES];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"导航.png"] forBarMetrics:UIBarMetricsDefault];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"dress_icon"] style:UIBarButtonItemStylePlain target:self action:@selector(leftClick)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"massage_icon"] style:UIBarButtonItemStylePlain target:self action:@selector(rightClick)];
    
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, GyyScreenW-100, 29)];
    view.backgroundColor = [UIColor whiteColor];
    view.layer.cornerRadius = 5;
    view.layer.masksToBounds = YES;
    UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(5, 0, 20, 20)];
    imageV.centerY = view.centerY;
    imageV.image = [UIImage imageNamed:@"search_icon"];
    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(30, 0, GyyScreenW-100-30, 29)];
    textField.borderStyle = UITextBorderStyleNone;
    textField.placeholder = @"搜索服务";
//    textField.layer.cornerRadius = 5;
//    textField.layer.masksToBounds = YES;
    textField.delegate = self;
    textField.backgroundColor = [UIColor whiteColor];
    [view addSubview:textField];
    [view addSubview:imageV];
    self.navigationItem.titleView = view;
 
//    [textField setValue:[UIFont systemFontOfSize:14]forKeyPath:@"_placeholderLabel.font"];//修改字体
//    [textField setValue:@(NSTextAlignmentCenter) forKey:@"_placeholderLabel.textAlignment"];
  
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
        // 设置item尺寸
        layout.itemSize = CGSizeMake(GyyScreenW/3, (GyyScreenH-64-50-130)/4);
        // 设置item之间的间隔
        layout.minimumInteritemSpacing = 0;
        // 设置行之间间隔
//        layout.minimumLineSpacing = 20;
        // 设置组的内边距
//        layout.sectionInset = UIEdgeInsetsMake(20, 0, 0, 0);
    UICollectionView *collect = [[UICollectionView alloc]initWithFrame:CGRectMake(0,0, GyyScreenW, GyyScreenH-50) collectionViewLayout:layout];
    collect.backgroundColor = [UIColor whiteColor];
    [collect registerNib:[UINib nibWithNibName:NSStringFromClass([HeadVieCell class]) bundle:nil] forCellWithReuseIdentifier:cellStr];
    [collect registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerId];
    collect.delegate = self;
    collect.dataSource = self;
    [self.view addSubview:collect];
    
    // Do any additional setup after loading the view from its nib.
}



-(NSMutableArray *)textArr
{
    if (!_textArr) {
//        _textArr = [NSMutableArray arrayWithObjects:@"报修服务",@"缴费服务",@"物联服务",@"信息服务",@"便民服务",@"公示公告",@"意见反馈",@"爱心邻里",@"房产服务",@"智慧出行",@"小区商城",@"支付管理", nil];
        _textArr = [NSMutableArray array];
        NSArray *arr1 = [NSArray arrayWithObjects:@"报修服务",@"缴费服务",@"物联服务", nil];
          NSArray *arr2 = [NSArray arrayWithObjects:@"信息服务",@"便民服务",@"公示公告", nil];
          NSArray *arr3 = [NSArray arrayWithObjects:@"意见反馈",@"爱心邻里",@"房产服务", nil];
          NSArray *arr4 = [NSArray arrayWithObjects:@"智慧出行",@"小区商城",@"支付管理", nil];
        [_textArr addObject:arr1];
            [_textArr addObject:arr2];
            [_textArr addObject:arr3];
            [_textArr addObject:arr4];
    }
    return _textArr;
}
-(NSMutableArray *)imageArr
{
    if (!_imageArr) {
//        _imageArr = [NSArray arrayWithObjects:@"baoxiu_icon",@"jiaofei_icon-",@"wulian_icon",@"xinxi_icon",@"bianmin_icon",@"gonggao",@"yijian_icon",@"linli_icon",@"fangchan",@"chuxing_icon",@"shangcheng_icon",@"zhifu_icon", nil];
        _imageArr = [NSMutableArray array];
        NSArray *arr1 = [NSArray arrayWithObjects:@"baoxiu_icon",@"jiaofei_icon-",@"wulian_icon", nil];
        NSArray *arr2 = [NSArray arrayWithObjects:@"xinxi_icon",@"bianmin_icon",@"gonggao_icon", nil];
        NSArray *arr3 = [NSArray arrayWithObjects:@"yijian_icon",@"linli_icon",@"fangchan_icon", nil];
        NSArray *arr4 = [NSArray arrayWithObjects:@"chuxing_icon",@"shangcheng_icon",@"zhifu_icon", nil];
        [_imageArr addObject:arr1];
        [_imageArr addObject:arr2];
        [_imageArr addObject:arr3];
        [_imageArr addObject:arr4];
    }
    return _imageArr;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return 3;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HeadVieCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellStr forIndexPath:indexPath];
    cell.imageV.image = [UIImage imageNamed:self.imageArr[indexPath.section][indexPath.item]];
    cell.labelText.text = self.textArr[indexPath.section][indexPath.item];
    return cell;
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 4;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    ComMallViewController *com = [[ComMallViewController alloc]init];
    switch (indexPath.section) {
        case 0:
            switch (indexPath.item) {
                case 0:
                
                    break;
                case 1:
                    
                    break;
                case 2:

                    break;
                default:
                    break;
            }
            break;
        case 1:
            switch (indexPath.item) {
                case 0:
                    [self ploatSearch];
                    break;
                case 1:
                    [self handyService:HandyService];
                    break;
                case 2:
                    [self gongGao];
                    break;
                default:
                    break;
            }
            break;
        case 2:
            switch (indexPath.item) {
                case 0:
                    
                    break;
                case 1:
                    [self LinLi:citizen];
                    break;
                case 2:
                    
                    break;
                default:
                    break;
            }
            break;
        case 3:
            switch (indexPath.item) {
                case 0:
                    [self handyService:trip];
                    break;
                case 1:
                    [self.navigationController pushViewController:com animated:YES];
                    break;
                case 2:
                    
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}
//信息服务
-(void)ploatSearch
{
    PlotSearchVC *plotSearch = [[PlotSearchVC alloc]init];
    [self.navigationController pushViewController:plotSearch animated:YES];
}
//便民服务
-(void)handyService:(tripHandyService)type
{
    HandyServicVC *VC = [[HandyServicVC alloc]init];
    VC.tripServiceType = type;
    [self.navigationController pushViewController:VC animated:YES];
}
//公示公告
-(void)gongGao
{
    GongGaoVC *gonGao = [[GongGaoVC alloc]init];
    [self.navigationController pushViewController:gonGao animated:YES];
}
//爱心邻里
-(void)LinLi:(CitiHelpType)type
{
    LovingHeartVC *heart = [[LovingHeartVC alloc]init];
    heart.type = type;
    [self.navigationController pushViewController:heart animated:YES];
}

//跳转到历史记录
-(void)leftClick
{

}
-(void)rightClick
{
    NewViewContro *newC = [[NewViewContro alloc]init];
    [self.navigationController pushViewController:newC animated:YES];

}
//-(void)viewWillAppear:(BOOL)animated
//{
//    SDCycleScrollView *sdScroV = [self.view viewWithTag:1000];
//    [sdScroV adjustWhenControllerViewWillAppera];
//}


/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{

}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    
    if([kind isEqualToString:UICollectionElementKindSectionHeader])
    {
        UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:headerId forIndexPath:indexPath];
      
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, GyyScreenW, GyyScreenW*0.32)];
        SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, GyyScreenW,GyyScreenW*0.32) delegate:self placeholderImage:[UIImage imageNamed:@"测试"]];
            cycleScrollView.imageURLStringsGroup = [NSArray arrayWithObjects:@"测试",@"测试",@"测试",@"测试",nil];
            [headerView addSubview:view];
            [view addSubview:cycleScrollView];
        return headerView;
    }
  
    
    return nil;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return CGSizeMake(GyyScreenW, GyyScreenW*0.32);

    }
    return CGSizeMake(0, 0);
}
/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index
{

}
-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
    self.navigationController.navigationBar.hidden = NO;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
